const Koa =require("koa");
const Router =require("koa-router");

const serve =require("koa-static");

const view= require("koa-view");

const app=new Koa()
const router=new Router()

app.use(serve(__dirname+'/views'))
app.use(view(__dirname+'/views'))

router.get("/getList",async ctx=>{
    ctx.body="获取列表"
})

router.get("/getUserInfo",async ctx=>{
    ctx.body="获取用户信息"
})

router.get("/getGoods",async ctx=>{
    ctx.body="我是第三个接口"
})

app.use(async (ctx,next)=>{
    const{method,url,header}=ctx
    const{host}=header
    console.log(`我本次的请求方式为${method}---请求地址为${host}${url}`)
    await next()
})

app.use(async (ctx,next)=>{
    const{status}=ctx
    if(status==404){
        await ctx.render('./404')
    }
    await next()
})

app.use(router.routes())
app.listen(3456,()=>{
    console.log("http://127.0.0.1:3456")
})

const num = 0





